<?php
$width=Yii::app()->params['dialog']['findDonsignorForSchedule']['width'];
$height=Yii::app()->params['dialog']['findDonsignorForSchedule']['height'];
$width1=Yii::app()->params['dialog']['findPathForSchedule']['width'];
$height1=Yii::app()->params['dialog']['findPathForSchedule']['height'];
$width2=Yii::app()->params['dialog']['findGoodsNameForSchedule']['width'];
$height2=Yii::app()->params['dialog']['findGoodsNameForSchedule']['height'];
$cs=Yii::app()->clientScript;
$cs->registerScriptFile('./js/modal.js');
$cs->registerScript('consignor_schedule_dialog',<<<END
function Block(){\$.modal('?r=dialog/findDonsignorForSchedule',{width:$width,height:$height,title:'请选择货主(发货人)'});return false;}
function Block1(){\$.modal('?r=dialog/findPathForSchedule',{height:$height1,width:$width1,title:'请选择线路'});return false;}
function Block2(id){\$.modal('?r=dialog/findGoodsNameForSchedule&consignor_id='+id,{height:$height2,width:$width2,title:'请选择货物名称'});}
$("#findConsignor").click(Block);
$("#findPath").click(Block1);
$("#findGoodsName").click(function(){Block2($("#Schedule_list_fk_consignor_id").val());return false;});
function calculate_charge(){
	var vaild=true;
	var validator=$("form").validate();
	validator.resetForm();
	vaild=validator.element($("#Schedule_list_unit_price"))?vaild:false;
	vaild=validator.element($("#Schedule_list_amount"))?vaild:false;
	if($("#Schedule_list_unit_name").val()==4)
		vaild=validator.element($("#Schedule_list_mileage"))?vaild:false;
	if(!vaild) {alert('请将信息填写完整信息!');return;}
	
	var cost=parseFloat($("#Schedule_list_unit_price").val(),10)*parseFloat($("#Schedule_list_amount").val(),10);
	if($("#Schedule_list_unit_name").val()==4) cost*=parseFloat($("#Schedule_list_mileage").val(),10);
	$("#Schedule_list_freight_charge").val(Math.round(cost*100)/100);
}
$("#calculate_charge").click(calculate_charge);
function findGoodsName(){
	if($("#Schedule_list_consignor_name").val()!='') $("#findGoodsName").show(); else $("#findGoodsName").hide();
}
findGoodsName(); 
END
);
if(!$update){
	$sess=Yii::app()->session;
	$model->user_name=$sess['true_name'];
	$model->user_region=$sess['region'];
	$model->fk_user_id=$sess['id'];
}
?>
<div class="yiiForm">
<?php
	echo EHtml::form();	
	EHtml::setOptions(array('errorElement'=> 'span'));
	EHtml::setScenario($update ? 'update' : 'create');				  		
?>
<div>注：<span class="required">*</span>为必填项</div>
<div id="leftaa" style="width:390px;">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'consignor_name'); ?>
<?php echo EHtml::activeTextField($model,'consignor_name',array('size'=>19,'class'=>'readonly','readOnly'=>'true')); ?>
<?php echo CHtml::activeHiddenField($model,'fk_consignor_id');?>&nbsp;&nbsp;<a id="findConsignor" href="#">查找货主</a>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'deliver_place'); ?>
<?php echo EHtml::activeTextField($model,'deliver_place',array('size'=>12,'class'=>'readonly','readOnly'=>'true')); ?>
<?php echo CHtml::activeHiddenField($model,'fk_path_id');?>&nbsp;&nbsp;<a id="findPath" href="#">查找线路</a>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'arrival_place'); ?>
<?php echo EHtml::activeTextField($model,'arrival_place',array('size'=>12,'class'=>'readonly','readOnly'=>'true')); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'mileage'); ?>
<?php echo EHtml::activeTextField($model,'mileage',array('size'=>7,'class'=>'readonly','readOnly'=>'true')); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'goods_name'); ?>
<?php echo EHtml::activeTextField($model,'goods_name',array('size'=>15,'class'=>'readonly','readOnly'=>'true')); ?>
<?php echo CHtml::activeHiddenField($model,'fk_goods_name_id');?>&nbsp;&nbsp;<a id="findGoodsName" style="display:none" href="#">查找货物名称</a>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'deliver_time'); ?>
<?php echo EHtml::activeTextField($model,'deliver_time',array('id'=>'deliver_time','size'=>15,'value'=>substr($model->deliver_time,0,16))); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'deliver_time','ifFormat'=>'%Y-%m-%d %H:%M','showsTime'=>true));?>
</div>
<div class="simple" style="border-bottom:0px;">
<?php echo CHtml::activeLabelEx($model,'arrival_time'); ?>
<?php echo EHtml::activeTextField($model,'arrival_time',array('id'=>'arrival_time','size'=>15,'value'=>substr($model->deliver_time,0,16))); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'arrival_time','ifFormat'=>'%Y-%m-%d %H:%M','showsTime'=>true));?>
</div>

</div>
  <div id="rightaa" style="width:344px;">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'unit_name'); ?>
<?php echo EHtml::activeDropDownList($model,'unit_name',$model->getUnitNames()); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'unit_price'); ?>
<?php echo EHtml::activeTextField($model,'unit_price',array('size'=>8)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'amount'); ?>
<?php echo EHtml::activeTextField($model,'amount',array('size'=>8)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'freight_charge'); ?>
<?php echo EHtml::activeTextField($model,'freight_charge',array('size'=>8)); ?><input id="calculate_charge" type="button" value="计算"/>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'user_name'); ?>
<?php echo EHtml::activeTextField($model,'user_name',array('class'=>'readonly','readOnly'=>'true','size'=>8)); ?>
<?php echo CHtml::activeHiddenField($model,'fk_user_id');?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'user_region'); ?>
<?php echo EHtml::activeTextField($model,'user_region',array('class'=>'readonly','readOnly'=>'true','size'=>15)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'distributor'); ?>
<?php echo EHtml::activeTextField($model,'distributor',array('size'=>8,'maxlength'=>30)); ?>
</div>
</div>
<div class="action">
<?php echo EHtml::submitButton($update ? '更新信息' : '添加信息'); ?>
</div>

<?php echo EHtml::endForm(); ?>

</div><!-- yiiForm -->